module.exports = async () => {
    const sequelize = require("./index");

    const enWord = require("./enWords");
    const dailySentence = require("./dailySentence");
    const banner = require("./banner");
    const extendArticle = require("./extendArticle");
    const extendArticleType = require("./extendArticleType");
    const etymology = require("./etymology");
    const etymologyType = require("./etymologyType");

    const Product = require("./product");
    const ProductImage = require("./productImage");
    const ProductLabel = require("./productLabel");
    const Type = require("./type");
    const Order = require("./order");
    const User = require("./user");

    sequelize.sync(); //如果有表则跳过
    // sequelize.sync({ force: true }) // - 将创建表,如果表已经存在,则将其首先删除
    // sequelize.sync({ alter: true }) // - 这将检查数据库中表的当前状态(它具有哪些列,它们的数据类型等),然后在表中进行必要的更改以使其与模型匹配.
    // sequelize.drop(); // 删除所有表

    try {
        await sequelize.sync({ alter: true });

        await extendArticle.associate({ extendArticleType });
        await extendArticleType.associate({ extendArticle });

        await etymology.associate({ etymologyType });
        await etymologyType.associate({ etymology });

        Type.associate({ Product });

        Product.associate({
            Type,
            ProductLabel,
            ProductImage,
            Order,
        });

        ProductLabel.associate({ Product });

        ProductImage.associate({ Product });

        Order.associate({ Product, User });

        User.associate({
            Order,
        });
    } catch (e) {
        console.error(e);
    }
};
